import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import paths from '@/components/paths'
import path_show from '@/components/path_show'
import bootcamp from '@/components/bootcamp'
import courses from '@/components/courses'
import course_show from '@/components/course_show'
import vip from '@/components/vip'
import questions from '@/components/questions'
import question_show from '@/components/question_show'
import privacy from '@/components/privacy'
import testcom from '@/components/testcom'
import user from '@/components/user'
import user_profile from '@/components/user_profile'
import tripalogin from '@/components/tripalogin'
import section_show from '@/components/section_show'
import users from '@/components/users'
import coupon from '@/components/coupon'
import web_shell from '@/components/web_shell'
import search from '@/components/search'
import login from '@/components/login'
import test from '@/components/test/father'
import books from '@/views/books'
import Login2 from '@/views/Login'
import Dingding from '@/components/dingding'
import Weibo from '@/components/weibo'
import UploadVideo from '@/components/common/upload_video'
import add_course from '@/views/add_course'
import add_chapters from '@/views/add_chapters'
import add_sections from '@/views/add_sections'
import change_password from '@/views/change_password'

Vue.use(Router)

// 路由拦截
var check_login = (to, from, next) => {
    // 判断是否登录
    if (localStorage.getItem("uid")) {
        next()
    } else {
        alert("尚未登录，请先登录")
        next("/")
    }
};

var routes = [    
    {
    path: '/change_password',
    name: 'change_password',
    component: change_password 
    },
    {
    path: '/add_sections',
    name: 'add_sections',
    component: add_sections
    },
    {
        path: '/add_chapters',
        name: 'add_chapters',
        component: add_chapters
    },
    {
        path: '/add_course',
        name: 'add_course',
        component: add_course
    },
    // 领取优惠券
    {
        path: '/coupon',
        name: 'coupon',
        component: coupon
    },
    {
        path: '/section_show',
        name: 'section_show',
        component: section_show
    },
    {
        path: '/user_profile',
        name: 'user_profile',
        component: user_profile
    },
    {
        path: '/user',
        name: 'user',
        component: user,
        beforeEnter: check_login,
    },
    {
        path: '/testcom',
        name: 'testcom',
        component: testcom
    },
    {
        path: '/privacy',
        name: 'privacy',
        component: privacy
    },
    {
        path: '/questions/question_show',
        name: 'question_show',
        component: question_show
    },
    {
        path: '/questions',
        name: 'questions',
        component: questions
    },
    {
        path: '/vip',
        name: 'vip',
        component: vip
    },
    {
        path: '/courses/course_show',
        name: 'course_show',
        component: course_show
    },
    {
        path: '/courses',
        name: 'courses',
        component: courses
    },
    {
        path: '/bootcamp',
        name: 'bootcamp',
        component: bootcamp
    },
    {
        path: '/paths/path_show',
        name: 'path_show',
        component: path_show
    },
    {
        path: '/paths',
        name: 'paths',
        component: paths
    },
    {
        path: '/',
        name: 'index',
        component: index,
    },
    {
        path: '/tripalogin',
        name: 'tripalogin',
        component: tripalogin,
    },
    {
        path: '/users',
        name: 'users',
        component: users,
    },
    {
        path: '/web_shell',
        name: 'web_shell',
        component: web_shell,
    },
    {
        path: '/search',
        name: 'search',
        component: search,
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },
    {
        path: '/test',
        name: 'test',
        component: test
    },
    {
        path: '/book',
        name: 'book',
        component: books
    },
    {
        path: '/login2',
        name: 'login2',
        component: Login2
    },
    {
        path: '/dingding_back',
        name: 'dingding_back',
        component: Dingding
    },
    {
        path: '/upload_video',
        name: 'upload_video',
        component: UploadVideo
    },
    {
        path: '/weibo',
        name: 'weibo',
        component: Weibo
    },
]


export default new Router({
    routes: routes,
    mode: 'history' /*hash*/
})